<template>
	<view class="con">
		<view class="box">
			<!-- 1，左侧标题 -->
			<view class="box-left">
				<view class="box-left-img">
					<image :src="inputData.titleImg"></image>
				</view>
				<view class="box-left-title">
					<text v-if="inputData.isRequired" style="color: red;">*</text>
					<text>{{inputData.title}}</text>
				</view>
			</view>
			<!-- 2，中间input框 -->
			<view class="box-right" @click="changeInputText">
				<input type="text" v-model="inputValue" @input="changeInputPrice"
					:placeholder="inputData.placeholderText"
					v-if="inputData.showType == 'input' && inputType == 'text'" />
				<input type="number" v-model="inputValue" @input="changeInputPrice"
					:placeholder="inputData.placeholderText"
					v-if="inputData.showType == 'input' && inputType == 'number'" />
				<text v-if="inputData.showType == 'text'">{{inputData.text}}</text>
				<image :src="gomoreImg" v-if="inputData.showType == 'text'"></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			inputData: {
				type: Object,
				default: {}
			},
			inputType: {
				type: String,
				default: 'text'
			}
		},
		data() {
			return {
				gomoreImg: require('@/static/img/common/goMore_1.svg'),
				inputValue: ''
			}
		},
		methods: {
			changeInputText() {
				if (this.inputData.showType == 'text') {
					this.$emit('changeInputText')
				}
			},
			changeInputPrice(e) {
				//正则表达试
				e.target.value = e.target.value.match(/^\d*(\.?\d{0,2})/g)[0] || null;
				//重新赋值给input
				this.$nextTick(() => {
					var amount = e.target.value;
					this.inputValue = amount
					this.$emit('changeInputPrice', parseFloat(amount))
				});

				//this.$emit('changeInputPrice', this.inputValue)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.con {
		width: 100%;
		background-color: #fff;

		&:active {
			background-color: #eee;
		}

		.box {
			width: 92%;
			margin-left: 4%;
			height: 100rpx;
			display: flex;
			// border-bottom: 1rpx solid #eee;

			.box-left {
				width: 35%;
				display: flex;

				.box-left-img {
					image {
						height: 40rpx;
						width: 40rpx;
						margin: 30rpx 15rpx 30rpx 15rpx;
					}
				}

				.box-left-title {
					font-size: 28rpx;
					line-height: 100rpx;
				}
			}

			.box-right {
				width: 65%;
				display: flex;
				justify-content: space-between;

				input {
					width: 100%;
					height: 60rpx;
					margin-top: 20rpx;
				}

				text {
					font-size: 28rpx;
					line-height: 100rpx;
				}

				image {
					margin-top: 30rpx;
					width: 40rpx;
					height: 40rpx;
				}
			}
		}
	}
</style>